cmake_minimum_required(VERSION 3.29)
project(capture C)

set(CMAKE_C_STANDARD 99)
add_definitions(-DLUA_32BITS)
find_package(PkgConfig REQUIRED)
pkg_check_modules(GLIB REQUIRED glib-2.0)
pkg_check_modules(PCAP REQUIRED libpcap)
set(NGHTTP2_INCLUDE_DIRS /usr/local/include/nghttp2)
set(NGHTTP2_LIBRARIES /usr/local/lib/libnghttp2.a)

set(YARA_INCLUDE_DIRS /usr/local/include/yara)
set(YARA_LIBRARIES /usr/local/lib/libyara.a)

set(DAQ_LIBRARIES
        /usr/local/lib/daq/daq_afpacket.so
        /usr/local/lib/daq/daq_dump.so
        /usr/local/lib/daq/daq_ipfw.so
        /usr/local/lib/daq/daq_pcap.so)
set(DAQ_INCLUDE_DIRS /usr/local/include/daq_api.h /usr/local/include/daq_common.h /usr/local/include/daq.h)

set(LUA_LIBRARIES /usr/local/lib/liblua.a)
set(LUA_INCLUDE_DIRS /usr/local/include/lua*)

set(KAFKA_LIBRARIES /usr/local/lib/librdkafka.a)
set(KAFKA_INCLUDE_DIRS /usr/local/include/librdkafka)

#find_package(YARA REQUIRED)

message(STATUS "GLIB_INCLUDE_DIRS:${GLIB_INCLUDE_DIRS} GLIB_LIBRARIES:${GLIB_LIBRARIES}")
message(STATUS "PCAP_INCLUDE_DIRS:${PCAP_INCLUDE_DIRS} PCAP_LIBRARIES:${PCAP_LIBRARIES}")
message(STATUS "NGHTTP2_INCLUDE_DIRS:${NGHTTP2_INCLUDE_DIRS} NGHTTP2_LIBRARIES:${NGHTTP2_LIBRARIES}")
message(STATUS "YARA_INCLUDE_DIRS:${YARA_INCLUDE_DIRS} YARA_LIBRARIES:${YARA_LIBRARIES}")
message(STATUS "DAQ_INCLUDE_DIRS:${DAQ_INCLUDE_DIRS} DAQ_LIBRARIES:${DAQ_LIBRARIES}")
message(STATUS "LUA_INCLUDE_DIRS:${LUA_INCLUDE_DIRS} LUA_LIBRARIES:${LUA_LIBRARIES}")
message(STATUS "KAFKA_INCLUDE_DIRS:${KAFKA_INCLUDE_DIRS} KAFKA_LIBRARIES:${KAFKA_LIBRARIES}")



include_directories(
        ${PROJECT_SOURCE_DIR}
        ${NGHTTP2_INCLUDE_DIRS}
        ${GLIB_INCLUDE_DIRS}
        ${PCAP_INCLUDE_DIRS}
        ${YARA_INCLUDE_DIRS}
        ${DAQ_INCLUDE_DIRS}
        ${LUA_INCLUDE_DIRS}
        ${KAFKA_INCLUDE_DIRS}

)
file(GLOB_RECURSE SOURCES
        "${PROJECT_SOURCE_DIR}/*.c"
        "${PROJECT_SOURCE_DIR}/thirdparty/*.c"
        "${PROJECT_SOURCE_DIR}/parsers/*.c"
        "plugins/*.c"
        "plugins/daq/*.c"
        "plugins/kafka/kafka.c"
        "plugins/lua/*.c"
)
# 针对每个解析器创建一个共享库
file(GLOB_RECURSE PARSER_SOURCES "${PROJECT_SOURCE_DIR}/parsers/*.c")
foreach(PARSER_SRC ${PARSER_SOURCES})
    get_filename_component(PARSER_NAME ${PARSER_SRC} NAME_WE)
    add_library(${PARSER_NAME} SHARED ${PARSER_SRC})
    target_link_libraries(${PARSER_NAME} PRIVATE pthread)
endforeach()
add_subdirectory(${CMAKE_SOURCE_DIR}/parsers)
add_executable(capture ${SOURCES})
target_link_libraries(capture

        ${NGHTTP2_LIBRARIES}
        ${GLIB_LIBRARIES}
        ${PCAP_LIBRARIES}
        ${YARA_LIBRARIES}
        ${DAQ_LIBRARIES}
        ${LUA_LIBRARIES}
        ${KAFKA_LIBRARIES}
        libparser
)
